package com.zx.znav.controller.user;

import com.zx.znav.bean.Link;
import com.zx.znav.constant.Constants;
import com.zx.znav.controller.vo.UserVO;
import com.zx.znav.service.LinkService;
import com.zx.znav.service.LinkStarService;
import com.zx.znav.utils.UserHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * @author 挚爱之夕
 * @version 1.0
 * @implSpec 个人书签
 * @since 2023-08-15 14:46
 */
@Controller
@RequestMapping("/user/bookmark")
public class BookMarkController {
    @Autowired
    private LinkStarService linkStarService;
    @Autowired
    private LinkService linkService;
    @GetMapping
    public String index(Model model){
        return "bookmark";
    }
    @GetMapping("/star")
    public String starLink(Model model){
        UserVO user = UserHolder.getUser();
        List<Integer> linkIds = linkStarService.listStarLink(user.getId());
        if(linkIds.size() > 0){
            List<Link> links = linkService.listByIds(linkIds);
            model.addAttribute(Constants.LinKS_KEY, links);
        }
        return "bookmark :: linkContent";
    }
}
